#import "QuickpassFlutterPlugin.h"
#if __has_include(<quickpass_flutter_plugin/quickpass_flutter_plugin-Swift.h>)
#import <quickpass_flutter_plugin/quickpass_flutter_plugin-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#endif
#import <NTESQuickPass/NTESQuickPass.h>

@interface QuickpassFlutterPlugin()<NTESQuickLoginManagerDelegate>

@property (nonatomic, copy) NSDictionary *params;
@property (nonatomic, copy) NSDictionary *option;
@property (nonatomic, strong) NSMutableDictionary *callBackDict;

@property (nonatomic, copy) FlutterResult customViewCallback;

@property (nonatomic, strong) FlutterEventChannel* eventChannel;

@end

@implementation QuickpassFlutterPlugin

+ (QuickpassFlutterPlugin *)sharedInstance {
    static dispatch_once_t onceToken = 0;
    static QuickpassFlutterPlugin *sharedObject = nil;
    dispatch_once(&onceToken, ^{
        sharedObject = [[QuickpassFlutterPlugin alloc] init];
    });
    
    return sharedObject;
}

NSObject<FlutterPluginRegistrar>* _quickpass_jv_registrar;

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"quicklogin_flutter_plugin"
                                                                binaryMessenger:[registrar messenger]];
    _quickpass_jv_registrar = registrar;
    QuickpassFlutterPlugin* instance = [QuickpassFlutterPlugin sharedInstance];
    instance.channel = channel;
    [registrar addMethodCallDelegate:instance channel:channel];
    
    // FlutterViewController *view = (FlutterViewController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    // if ([view isKindOfClass:[UINavigationController class]]) {
    //     UINavigationController *nav = (UINavigationController *)view;
    //     view = (FlutterViewController *)nav.topViewController;
    // }
    FlutterEventChannel* eventChannel= [FlutterEventChannel  eventChannelWithName:@"yd_quicklogin_flutter_event_channel" binaryMessenger:[registrar messenger]];
    instance.eventChannel = eventChannel;
    [eventChannel setStreamHandler:instance];
}

- (FlutterError* _Nullable)onListenWithArguments:(id _Nullable)arguments
                                       eventSink:(FlutterEventSink)events {
    if (events) {
        [QuickpassFlutterPlugin sharedInstance].eventSink = events;
    }
    
    return nil;
}

- (FlutterError * _Nullable)onCancelWithArguments:(id _Nullable)arguments {
    return nil;
}


- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
    NSString *methodName = call.method;
    if ([methodName isEqualToString:@"init"]) {
        [self init:call result:result];
    } else if ([methodName isEqualToString:@"preFetchNumber"]){
        [self preFetchNumber:call result:result];
    } else if ([methodName isEqualToString:@"onePassLogin"]) {
        [self onePassLogin:call result:result];
    } else if ([methodName isEqualToString:@"setUiConfig"]) {
        [self setCustomAuthorizationView:call result:result];
    } else if ([methodName isEqualToString:@"closeLoginAuthView"]) {
        [self closeAuth];
    } else if ([methodName isEqualToString:@"checkVerifyEnable"]) {
        [self checkVerifyEnable:call result:result];
    } else if ([methodName isEqualToString:@"verifyPhoneNumber"]) {
        [self verifyPhoneNumber:call result:result];
    } else if ([methodName isEqualToString:@"authLoginButtonClick"]) {
        [self authLoginButtonClick:call result:result];
    } else if ([methodName isEqualToString:@"checkedSelected"]) {
        [self checkedSelected:call result:result];
    }  else {
        result(FlutterMethodNotImplemented);
    }
}

- (void)checkedSelected:(FlutterMethodCall*) call result:(FlutterResult)resultDict {
    NSString *arguments = call.arguments;
    if ([arguments isEqualToString:@"true"]) {
        [NTESQuickLoginManager sharedInstance].model.checkedSelected = YES;
    } else {
        [NTESQuickLoginManager sharedInstance].model.checkedSelected = NO;
    }
}

- (void)authLoginButtonClick:(FlutterMethodCall*) call result:(FlutterResult)resultDict {
    [[NTESQuickLoginManager sharedInstance] authLoginButtonClick];
}

- (void)verifyPhoneNumber:(FlutterMethodCall*) call result:(FlutterResult)resultDict {
    self.callBackDict = [NSMutableDictionary dictionary];
    NSDictionary *arguments = call.arguments;
    NSString *businessId = [arguments objectForKey:@"businessId"];
    NSString *phoneNumber = [arguments objectForKey:@"phoneNumber"];
    if (![phoneNumber isKindOfClass:[NSString class]]) {
        NSLog(@"传入的phoneNumber无效.");
        return;
    }
    if (![businessId isKindOfClass:[NSString class]]) {
        NSLog(@"传入的businessId无效.");
        return;
    }
    
    [[NTESQuickPassManager sharedInstance] verifyPhoneNumber:phoneNumber businessID:businessId completion:^(NSDictionary * _Nullable params, NTESQPStatus status, BOOL success) {
        NSString *accessToken = [params objectForKey:@"accessToken"];
        NSString *ydToken = [params objectForKey:@"token"];
        NSString *msg = @"";
        if (status == NTESQPPhoneNumInvalid) {
            msg = @"手机号不合法";
        } else if (status == NTESQPNonGateway) {
            msg = @"当前网络环境不可网关验证";
        } else if (status == NTESQPAccessTokenSuccess) {
            msg = @"获取accessToken成功";
        } else if (status == NTESQPAccessTokenFailure) {
            msg = @"获取accessToken失败";
        } else if (status == NTESQPAccessTokenTimeout) {
            msg = @"获取accessToken超时";
        }
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:ydToken?:@"" forKey:@"ydToken"];
        [dict setValue:accessToken?:@"" forKey:@"accessToken"];
        [dict setValue:msg?:@"" forKey:@"msg"];
        [dict setValue:@(success) forKey:@"success"];
        resultDict(dict);
    }];
}

- (void)init:(FlutterMethodCall*) call result:(FlutterResult)resultDict {
    self.callBackDict = [NSMutableDictionary dictionary];
    NSDictionary *arguments = call.arguments;
    NSString *businessId = [arguments objectForKey:@"businessId"];
    //    int timeout = ;
    //    timeout = timeout * 1000;
    //    [[NTESQuickLoginManager sharedInstance] setTimeoutInterval:timeout];
    //    NSString *loginType = [arguments objectForKey:@"loginType"];
    NSTimeInterval time = 0;
    if ([[arguments objectForKey:@"timeout"] isKindOfClass:[NSNumber class]]) {
        time = [[arguments objectForKey:@"timeout"] integerValue] * 1000;
        [[NTESQuickLoginManager sharedInstance] setTimeoutInterval:time];
    }
    [NTESQuickLoginManager sharedInstance].delegate = self;
    [[NTESQuickLoginManager sharedInstance] registerWithBusinessID:businessId];
    resultDict(@{@"success":@YES});
}

- (void)preFetchNumber:(FlutterMethodCall*)call result:(FlutterResult)resultDict {
    [[NTESQuickLoginManager sharedInstance] getPhoneNumberCompletion:^(NSDictionary * _Nonnull resultDic) {
        resultDict(resultDic);
    }];
}

- (void)onePassLogin:(FlutterMethodCall*)call result:(FlutterResult)resultDict {
    NSDictionary *arguments = call.arguments;
    BOOL animated = [[arguments objectForKey:@"animated"] boolValue];
    [[NTESQuickLoginManager sharedInstance] CUCMCTAuthorizeLoginCompletion:^(NSDictionary * _Nonnull resultDic) {
        resultDict(resultDic);
    } animated:animated];
}

- (void)closeAuth {
    [[NTESQuickLoginManager sharedInstance] closeAuthController:^{
        
    }];
}

- (void)checkVerifyEnable:(FlutterMethodCall*)call result:(FlutterResult)resultDict {
    BOOL shouldQuickLogin = [NTESQuickLoginManager sharedInstance].shouldQuickLogin;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@(shouldQuickLogin) forKey:@"success"];
    resultDict(dict);
}

- (void)setCustomAuthorizationView:(FlutterMethodCall*)call result:(FlutterResult)resultDict {
    self.customViewCallback = resultDict;
    NSDictionary *dict = call.arguments;
    if ([dict isKindOfClass:[NSDictionary class]]) {
        dict = [dict objectForKey:@"uiConfig"];
    }
    self.option = [dict mutableCopy];
    
    NTESQuickLoginModel *customModel = [[NTESQuickLoginModel alloc] init];
    customModel.customViewBlock = ^(UIView * _Nullable customView) {
        [customView setNeedsLayout];
        NSArray *widgets = [dict objectForKey:@"widgets"];
        for (NSInteger i = 0; i < widgets.count; i++) {
            NSDictionary *widgetsDict = widgets[i];
            NSString *type = [widgetsDict objectForKey:@"type"];
            if ([type isEqualToString:@"UIButton"]) {
                //                int buttonType = [[widgetsDict objectForKey:@"UIButtonType"] intValue];
                NSString *title = [widgetsDict objectForKey:@"title"];
                NSString *titleColor = [widgetsDict objectForKey:@"titleColor"];

                int cornerRadius = [[widgetsDict objectForKey:@"cornerRadius"] intValue];
                NSDictionary *frame = [widgetsDict objectForKey:@"frame"];
                NSString *image = [widgetsDict objectForKey:@"image"];
                NSString *backgroundColor = [widgetsDict objectForKey:@"backgroundColor"];
                NSString *backgroundImage = [widgetsDict objectForKey:@"backgroundImage"];
                
                int mainScreenLeftDistance = [[frame objectForKey:@"mainScreenLeftDistance"] intValue];
                int mainScreenRightDistance = [[frame objectForKey:@"mainScreenRightDistance"] intValue];
                int mainScreenCenterXWithLeftDistance = [[frame objectForKey:@"mainScreenCenterXWithLeftDistance"] intValue];
                int mainScreenBottomDistance = [[frame objectForKey:@"mainScreenBottomDistance"] intValue];
                int mainScreenTopDistance = [[frame objectForKey:@"mainScreenTopDistance"] intValue];
                int width = [[frame objectForKey:@"width"] intValue];
                int height = [[frame objectForKey:@"height"] intValue];
                
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setImage:[self loadImageWithName:image] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(buttonDidTipped:) forControlEvents:UIControlEventTouchUpInside];
                button.tag = i;
                [button setTitle:title forState:UIControlStateNormal];
                [button setTitleColor:[self ntes_colorWithHexString:titleColor] forState:UIControlStateNormal];

                if ([widgetsDict.allKeys containsObject:@"titleFont"]) {
                    int titleFont = [[widgetsDict objectForKey:@"titleFont"] intValue];
                    button.titleLabel.font = [UIFont systemFontOfSize:titleFont];
                } else {
                    int numberFontSize = [[widgetsDict objectForKey:@"numberFontSize"] intValue];
                    NSString *numberFontWeight = [widgetsDict objectForKey:@"numberFontWeight"];
                    if ([numberFontWeight isEqualToString:@"bold"]) {
                        button.titleLabel.font = [UIFont systemFontOfSize:numberFontSize weight:UIFontWeightBold];
                    }
                    if ([numberFontWeight isEqualToString:@"thin"]) {
                        button.titleLabel.font = [UIFont systemFontOfSize:numberFontSize weight:UIFontWeightThin];
                    }
                    if ([numberFontWeight isEqualToString:@"regular"]) {
                        button.titleLabel.font = [UIFont systemFontOfSize:numberFontSize weight:UIFontWeightRegular];
                    }
                }

                // 按钮边框粗细
                if ([widgetsDict.allKeys containsObject:@"borderWidth"]) {
                    int borderWidth = [[widgetsDict objectForKey:@"borderWidth"] intValue];
                    button.layer.borderWidth = borderWidth;
                }
                // 按钮边框颜色
                if ([widgetsDict.allKeys containsObject:@"borderColor"]) {
                    NSString *borderColor = [widgetsDict objectForKey:@"borderColor"];
                    button.layer.borderColor = [self ntes_colorWithHexString:borderColor].CGColor;
                }
                
                button.layer.cornerRadius = cornerRadius;
                button.layer.masksToBounds = YES;
                button.backgroundColor = [self ntes_colorWithHexString:backgroundColor];
                [button setBackgroundImage:[self loadImageWithName:backgroundImage] forState:UIControlStateNormal];
                [customView addSubview:button];
                if (mainScreenLeftDistance > 0 && mainScreenRightDistance > 0) {
                    if (mainScreenTopDistance > 0) {
                        button.frame = CGRectMake(mainScreenLeftDistance, mainScreenTopDistance, [UIScreen mainScreen].bounds.size.width - mainScreenLeftDistance - mainScreenRightDistance, height);
                    } else {
                        button.frame = CGRectMake(mainScreenLeftDistance, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, [UIScreen mainScreen].bounds.size.width - mainScreenLeftDistance - mainScreenLeftDistance, height);
                    }
                } else if (mainScreenLeftDistance == 0 && mainScreenRightDistance == 0) {
                    if (mainScreenTopDistance > 0) {
                        button.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - width)/2 - mainScreenCenterXWithLeftDistance, mainScreenTopDistance,width, height);
                    } else {
                        button.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - width)/2, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, width, height);
                    }
                } else if (mainScreenLeftDistance > 0 && mainScreenRightDistance == 0) {
                    if (mainScreenTopDistance > 0) {
                        button.frame = CGRectMake(mainScreenLeftDistance, mainScreenTopDistance, width, height);
                    } else {
                        button.frame = CGRectMake(mainScreenLeftDistance, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, width, height);
                    }
                } else if (mainScreenRightDistance > 0 && mainScreenLeftDistance == 0) {
                    if (mainScreenTopDistance > 0) {
                        button.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - mainScreenRightDistance - width, mainScreenTopDistance, width, height);
                    } else {
                        button.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - mainScreenRightDistance - width, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, width, height);
                    }
                }
                
            } else if ([type isEqualToString:@"UILabel"]) {
                NSDictionary *widgetsDict = widgets[i];
                NSString *type = [widgetsDict objectForKey:@"type"];
                NSString *text = [widgetsDict objectForKey:@"text"];
                NSString *textColor = [widgetsDict objectForKey:@"textColor"];
                NSString *backgroundColor = [widgetsDict objectForKey:@"backgroundColor"];
                
                int textAlignment = [[widgetsDict objectForKey:@"textAlignment"] intValue];
                int cornerRadius = [[widgetsDict objectForKey:@"cornerRadius"] intValue];
                NSDictionary *frame = [widgetsDict objectForKey:@"frame"];
                
                int mainScreenLeftDistance = [[frame objectForKey:@"mainScreenLeftDistance"] intValue];
                int mainScreenRightDistance = [[frame objectForKey:@"mainScreenRightDistance"] intValue];
                int mainScreenCenterXWithLeftDistance = [[frame objectForKey:@"mainScreenCenterXWithLeftDistance"] intValue];
                int mainScreenBottomDistance = [[frame objectForKey:@"mainScreenBottomDistance"] intValue];
                int mainScreenTopDistance = [[frame objectForKey:@"mainScreenTopDistance"] intValue];
                int width = [[frame objectForKey:@"width"] intValue];
                int height = [[frame objectForKey:@"height"] intValue];
                
                Class class = NSClassFromString(type);
                UILabel *label = (UILabel *)[[class alloc] init];
                label.tag = i;
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelDidTipped:)];
                [label addGestureRecognizer:tap];
                label.userInteractionEnabled = YES;
                label.text = text;
                label.layer.cornerRadius = cornerRadius;
                label.layer.masksToBounds = YES;
                label.textColor = [self ntes_colorWithHexString:textColor];
                // label.font = [UIFont systemFontOfSize:font];
                label.textAlignment = textAlignment;
                label.backgroundColor = [self ntes_colorWithHexString:backgroundColor];
                [customView addSubview:label];

                if ([widgetsDict.allKeys containsObject:@"font"]) {
                    int font = [[widgetsDict objectForKey:@"font"] intValue];
                    label.font = [UIFont systemFontOfSize:font];
                } else {
                    int numberFontSize = [[widgetsDict objectForKey:@"fontSize"] intValue];
                    NSString *numberFontWeight = [widgetsDict objectForKey:@"fontWeight"];
                    if ([numberFontWeight isEqualToString:@"bold"]) {
                        label.font = [UIFont systemFontOfSize:numberFontSize weight:UIFontWeightBold];
                    }
                    if ([numberFontWeight isEqualToString:@"thin"]) {
                        label.font = [UIFont systemFontOfSize:numberFontSize weight:UIFontWeightThin];
                    }
                    if ([numberFontWeight isEqualToString:@"regular"]) {
                        label.font = [UIFont systemFontOfSize:numberFontSize weight:UIFontWeightRegular];
                    }
                }

                CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
                if (mainScreenLeftDistance > 0 && mainScreenRightDistance > 0) {
                    if (mainScreenTopDistance > 0) {
                        label.frame = CGRectMake(mainScreenLeftDistance, mainScreenTopDistance, [UIScreen mainScreen].bounds.size.width - mainScreenLeftDistance - mainScreenRightDistance, height);
                    } else {
                        label.frame = CGRectMake(mainScreenLeftDistance, screenHeight - mainScreenBottomDistance -height, [UIScreen mainScreen].bounds.size.width - mainScreenLeftDistance - mainScreenLeftDistance, height);
                    }
                } else if (mainScreenLeftDistance == 0 && mainScreenRightDistance == 0) {
                    if (mainScreenTopDistance > 0) {
                        label.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - width)/2 - mainScreenCenterXWithLeftDistance, mainScreenTopDistance,width, height);
                    } else {
                        label.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - width)/2, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, width, height);
                    }
                } else if (mainScreenLeftDistance > 0 && mainScreenRightDistance == 0) {
                    if (mainScreenTopDistance > 0) {
                        label.frame = CGRectMake(mainScreenLeftDistance, mainScreenTopDistance, width, height);
                    } else {
                        label.frame = CGRectMake(mainScreenLeftDistance, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, width, height);
                    }
                } else if (mainScreenRightDistance > 0 && mainScreenLeftDistance == 0) {
                    if (mainScreenTopDistance > 0) {
                        label.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - mainScreenRightDistance - width, mainScreenTopDistance, width, height);
                    } else {
                        label.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - mainScreenRightDistance - width, [UIScreen mainScreen].bounds.size.height - mainScreenBottomDistance -height, width, height);
                    }
                }
            }
        }
    };
    customModel.backgroundColor = [self ntes_colorWithHexString:[dict objectForKey:@"backgroundColor"]];
    customModel.progressColor = [self ntes_colorWithHexString:[dict objectForKey:@"progressColor"]];
    customModel.bgImage = [self loadImageWithName:[dict objectForKey:@"bgImage"]];
    customModel.navTextFont = [UIFont systemFontOfSize:[[dict objectForKey:@"navTextFont"] intValue]];
    customModel.navText = [dict objectForKey:@"navText"];
    customModel.navTextColor = [self ntes_colorWithHexString:[dict objectForKey:@"navTextColor"]];
    customModel.navBgColor = [self ntes_colorWithHexString:[dict objectForKey:@"navBgColor"]];
    customModel.navTextHidden = [[dict objectForKey:@"navTextHidden"] boolValue];
    customModel.logoImg = [self loadImageWithName:[dict objectForKey:@"logoIconName"]];
    customModel.numberColor = [self ntes_colorWithHexString:[dict objectForKey:@"numberColor"]];

    if ([dict.allKeys containsObject:@"numberFont"]) {
        customModel.numberFont = [UIFont systemFontOfSize:[[dict objectForKey:@"numberFont"] intValue]];
    } else {
        customModel.numberFontSize = [[dict objectForKey:@"numberFontSize"] intValue];
        NSString *numberFontWeight = [dict objectForKey:@"numberFontWeight"];
        if ([numberFontWeight isEqualToString:@"bold"]) {
            customModel.numberFontWeight    = UIFontWeightBold;
        }
        if ([numberFontWeight isEqualToString:@"thin"]) {
            customModel.numberFontWeight    = UIFontWeightThin;
        }
        if ([numberFontWeight isEqualToString:@"regular"]) {
            customModel.numberFontWeight    = UIFontWeightRegular;
        }
    }

    customModel.brandColor = [self ntes_colorWithHexString:[dict objectForKey:@"brandColor"]];

    if ([dict.allKeys containsObject:@"brandFont"]) {
        customModel.brandFont = [UIFont systemFontOfSize:[[dict objectForKey:@"brandFont"] intValue]];
    } else {
        customModel.brandFontSize = [[dict objectForKey:@"brandFontSize"] intValue];
        NSString *brandFontWeight = [dict objectForKey:@"brandFontWeight"];
        if ([brandFontWeight isEqualToString:@"bold"]) {
            customModel.brandFontWeight    = UIFontWeightBold;
        }
        if ([brandFontWeight isEqualToString:@"thin"]) {
            customModel.brandFontWeight    = UIFontWeightThin;
        }
        if ([brandFontWeight isEqualToString:@"regular"]) {
            customModel.brandFontWeight    = UIFontWeightRegular;
        }
    }

    customModel.brandHidden = [[dict objectForKey:@"brandHidden"] boolValue];
    customModel.brandWidth = [[dict objectForKey:@"brandWidth"] intValue];
    customModel.brandHeight = [[dict objectForKey:@"brandHeight"] intValue];

    if ([dict.allKeys containsObject:@"loginBtnTextSize"]) {
        customModel.logBtnTextFont = [UIFont systemFontOfSize:[[dict objectForKey:@"loginBtnTextSize"] intValue]];
    } else {
        customModel.logBtnTextFontSize = [[dict objectForKey:@"logBtnTextFontSize"] intValue];
        NSString *logBtnTextFontWeight = [dict objectForKey:@"logBtnTextFontWeight"];
        if ([logBtnTextFontWeight isEqualToString:@"bold"]) {
            customModel.logBtnTextFontWeight    = UIFontWeightBold;
        }
        if ([logBtnTextFontWeight isEqualToString:@"thin"]) {
            customModel.logBtnTextFontWeight    = UIFontWeightThin;
        }
        if ([logBtnTextFontWeight isEqualToString:@"regular"]) {
            customModel.logBtnTextFontWeight    = UIFontWeightRegular;
        }
    }
    customModel.logBtnText = [dict objectForKey:@"logBtnText"];
    customModel.logBtnTextColor = [self ntes_colorWithHexString:[dict objectForKey:@"logBtnTextColor"]];
    customModel.logBtnUsableBGColor = [self ntes_colorWithHexString:[dict objectForKey:@"logBtnUsableBGColor"]];
    customModel.closePopImg = [self loadImageWithName:[dict objectForKey:@"closePopImg"]];
    customModel.numberBackgroundColor = [self ntes_colorWithHexString:[dict objectForKey:@"numberBackgroundColor"]];
    customModel.numberHeight = [[dict objectForKey:@"numberHeight"] intValue];
    customModel.numberCornerRadius = [[dict objectForKey:@"numberCornerRadius"] intValue];
    customModel.numberLeftContent = [dict objectForKey:@"numberLeftContent"];
    customModel.numberRightContent = [dict objectForKey:@"numberRightContent"];
    customModel.faceOrientation = (NTESInterfaceOrientation)[[dict objectForKey:@"faceOrientation"] intValue];
    customModel.logoHeight = [[dict objectForKey:@"logoHeight"] intValue];
    customModel.logoHidden = [[dict objectForKey:@"logoHidden"] boolValue];
    customModel.modalTransitionStyle = [[dict objectForKey:@"modalTransitionStyle"] intValue];

    if ([dict.allKeys containsObject:@"privacyFont"]) {
        customModel.privacyFont = [UIFont systemFontOfSize:[[dict objectForKey:@"privacyFont"] intValue]];
    } else {
        customModel.privacyFontSize = [[dict objectForKey:@"privacyFontSize"] intValue];
        NSString *privacyFontWeight = [dict objectForKey:@"privacyFontWeight"];
        if ([privacyFontWeight isEqualToString:@"bold"]) {
            customModel.privacyFontWeight    = UIFontWeightBold;
        }
        if ([privacyFontWeight isEqualToString:@"thin"]) {
            customModel.privacyFontWeight    = UIFontWeightThin;
        }
        if ([privacyFontWeight isEqualToString:@"regular"]) {
            customModel.privacyFontWeight    = UIFontWeightRegular;
        }
    }
    
    int loadingViewBlock = [[dict objectForKey:@"loadingViewBlock"] intValue];
    if (loadingViewBlock) {
        customModel.loadingViewBlock = ^(UIView * _Nullable customLoadingView) {
            
        };
    }
    
    
    customModel.appPrivacyText = [dict objectForKey:@"appPrivacyText"];
    customModel.appFPrivacyText = [dict objectForKey:@"appFPrivacyText"];
    customModel.appFPrivacyURL = [dict objectForKey:@"appFPrivacyURL"];
    customModel.appSPrivacyText = [dict objectForKey:@"appSPrivacyText"];
    customModel.appSPrivacyURL = [dict objectForKey:@"appSPrivacyURL"];
    customModel.appTPrivacyText = [dict objectForKey:@"appTPrivacyText"];
    customModel.appTPrivacyURL = [dict objectForKey:@"appTPrivacyURL"];
    
    customModel.appFourPrivacyText = [dict objectForKey:@"appFourPrivacyText"];
    customModel.appFourPrivacyURL = [dict objectForKey:@"appFourPrivacyURL"];
    
    customModel.appFourPrivacyTitleText = [dict objectForKey:@"appFourPrivacyTitleText"];
    customModel.appTPrivacyTitleText = [dict objectForKey:@"appTPrivacyTitleText"];
    customModel.appPrivacyOriginLeftMargin = [[dict objectForKey:@"appPrivacyOriginLeftMargin"] doubleValue];
    customModel.appPrivacyOriginRightMargin = [[dict objectForKey:@"appPrivacyOriginRightMargin"] doubleValue];
    int appPrivacyOriginBottomMargin = [[dict objectForKey:@"appPrivacyOriginBottomMargin"] intValue];
    if (appPrivacyOriginBottomMargin > 0) {
        customModel.appPrivacyOriginBottomMargin = appPrivacyOriginBottomMargin;
    }
    
    
    int appPrivacyOriginTopMargin = [[dict objectForKey:@"appPrivacyOriginTopMargin"] intValue];
    if (appPrivacyOriginTopMargin > 0) {
        customModel.appPrivacyOriginTopMargin = appPrivacyOriginTopMargin;
    }
    
    
    customModel.appFPrivacyTitleText = [dict objectForKey:@"appFPrivacyTitleText"];
    customModel.appPrivacyTitleText = [dict objectForKey:@"appPrivacyTitleText"];
    customModel.appSPrivacyTitleText = [dict objectForKey:@"appSPrivacyTitleText"];
    customModel.appPrivacyAlignment = [[dict objectForKey:@"appPrivacyAlignment"] intValue];
    customModel.isOpenSwipeGesture = [[dict objectForKey:@"isOpenSwipeGesture"] boolValue];
    customModel.logBtnOffsetTopY = [[dict objectForKey:@"logBtnOffsetTopY"] doubleValue];
    customModel.logBtnOffsetBottomY = [[dict objectForKey:@"logBtnOffsetBottomY"] doubleValue];
    customModel.logBtnHeight = [[dict objectForKey:@"logBtnHeight"] doubleValue];
    customModel.brandOffsetTopY = [[dict objectForKey:@"brandOffsetTopY"] doubleValue];
    customModel.brandOffsetBottomY = [[dict objectForKey:@"brandOffsetBottomY"] doubleValue];
    customModel.brandOffsetX = [[dict objectForKey:@"brandOffsetX"] doubleValue];
    customModel.numberOffsetTopY = [[dict objectForKey:@"numberOffsetTopY"] doubleValue];
    customModel.numberOffsetBottomY = [[dict objectForKey:@"numberOffsetBottomY"] doubleValue];
    customModel.numberOffsetX = [[dict objectForKey:@"numberOffsetX"] doubleValue];
    customModel.checkBoxAlignment = [[dict objectForKey:@"checkBoxAlignment"] intValue];
    customModel.checkBoxMargin = [[dict objectForKey:@"checkBoxMargin"] intValue];
    customModel.checkboxWH = [[dict objectForKey:@"checkboxWH"] intValue];
    customModel.checkedHidden = [[dict objectForKey:@"checkedHidden"] boolValue];
    customModel.checkedSelected = [[dict objectForKey:@"checkedSelected"] boolValue];
    customModel.checkedImg = [self loadImageWithName:[dict objectForKey:@"checkedImageName"]];
    //      customModel.checkedImg  = [UIImage imageWithName:@"checkedImageName" class:[self class]];
    customModel.uncheckedImg = [self loadImageWithName:[dict objectForKey:@"unCheckedImageName"]];
    //      customModel.uncheckedImg =  [UIImage imageWithName:@"unCheckedImageName" class:[self class]];
    customModel.logBtnOriginRight = [[dict objectForKey:@"logBtnOriginRight"] intValue];
    customModel.logBtnOriginLeft = [[dict objectForKey:@"logBtnOriginLeft"] intValue];
    
    
    customModel.logoOffsetTopY = [[dict objectForKey:@"logoOffsetTopY"] doubleValue];
    customModel.logoOffsetBottomY = [[dict objectForKey:@"logoOffsetBottomY"] doubleValue];
    customModel.logoOffsetX = [[dict objectForKey:@"logoOffsetX"] doubleValue];
    customModel.logBtnRadius = [[dict objectForKey:@"logBtnRadius"] intValue];
    customModel.logoWidth = [[dict objectForKey:@"logoWidth"] intValue];
    
    customModel.logoOffsetTopY = [[dict objectForKey:@"logoOffsetTopY"] doubleValue];
    customModel.logoOffsetX = [[dict objectForKey:@"logoOffsetX"] doubleValue];
    
    NSArray *colorStrs = [dict objectForKey:@"colors"];
    NSMutableArray *colors = @[].mutableCopy;
    for (NSString *color_str in colorStrs) {
        [colors addObject:(__bridge id)([self ntes_colorWithHexString:color_str].CGColor)];
    }

    if (colors.count > 0) {
        customModel.colors = colors;
        customModel.startPoint = CGPointMake([[dict objectForKey:@"startPointX"] doubleValue], [[dict objectForKey:@"startPointY"] doubleValue]);
        customModel.endPoint = CGPointMake([[dict objectForKey:@"endPointX"] doubleValue], [[dict objectForKey:@"endPointY"] doubleValue]);
    }
    
    customModel.brandBackgroundColor = [self ntes_colorWithHexString:[dict objectForKey:@"brandBackgroundColor"]];
    customModel.privacyColor = [self ntes_colorWithHexString:[dict objectForKey:@"privacyColor"]];
    customModel.protocolColor = [self ntes_colorWithHexString:[dict objectForKey:@"protocolColor"]];
    
    customModel.privacyNavReturnImg = [self loadImageWithName:[dict objectForKey:@"privacyNavReturnImg"]];
    customModel.navReturnImgHeight = [[dict objectForKey:@"navReturnImgHeight"] intValue];
    customModel.navReturnImgLeftMargin = [[dict objectForKey:@"navReturnImgLeftMargin"] intValue];
    customModel.navReturnImgWidth = [[dict objectForKey:@"navReturnImgWidth"] intValue];
    customModel.videoURL = [dict objectForKey:@"videoURL"];
    customModel.localVideoFileName = [dict objectForKey:@"localVideoFileName"];
    customModel.navReturnImgBottomMargin = [[dict objectForKey:@"navReturnImgBottomMargin"] intValue];
    customModel.modalTransitionStyle = [[dict objectForKey:@"modalTransitionStyle"] intValue];
    customModel.navReturnImg = [self loadImageWithName:[dict objectForKey:@"navReturnImg"]];
    customModel.logBtnHighlightedImg = [self loadImageWithName:[dict objectForKey:@"logBtnHighlightedImg"]];
    customModel.navBarHidden = [[dict objectForKey:@"navBarHidden"] boolValue];
    customModel.logBtnEnableImg = [self loadImageWithName:[dict objectForKey:@"logBtnEnableImg"]];
    int shouldHiddenPrivacyMarks = [[dict objectForKey:@"shouldHiddenPrivacyMarks"] intValue];
    if (shouldHiddenPrivacyMarks) {
        customModel.shouldHiddenPrivacyMarks = YES;
    } else {
        customModel.shouldHiddenPrivacyMarks = NO;
    }
    
    int navControl = [[dict objectForKey:@"navControl"] intValue];
    int navControlRightMargin = [[dict objectForKey:@"navControlRightMargin"] intValue];
    int navControlBottomMargin = [[dict objectForKey:@"navControlBottomMargin"] intValue];
    int navControlWidth = [[dict objectForKey:@"navControlWidth"] intValue];
    int navControlHeight = [[dict objectForKey:@"navControlHeight"] intValue];
    
    if (navControl) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        customModel.navControlRightMargin = navControlRightMargin;
        customModel.navControlBottomMargin = navControlBottomMargin;
        customModel.navControlWidth = navControlWidth;
        customModel.navControlHeight = navControlHeight;
        view.backgroundColor = [UIColor redColor];
        customModel.navControl = view;
    }
    
    customModel.isRepeatPlay = [[dict objectForKey:@"isRepeatPlay"] boolValue];
    
    customModel.animationRepeatCount = [[dict objectForKey:@"animationRepeatCount"] integerValue];
    NSArray *animationImages = [dict objectForKey:@"animationImages"];
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *image in animationImages) {
        [array addObject:[self loadImageWithName:[image objectForKey:@"imageName"]]];
    }
    customModel.animationImages = array;
    customModel.animationDuration = [[dict objectForKey:@"animationDuration"] integerValue];
    customModel.privacyState = [[dict objectForKey:@"privacyState"] boolValue];
    
    int authWindowPop = [[dict objectForKey:@"authWindowPop"] intValue];
    if (authWindowPop == 0) {
        customModel.authWindowPop = NTESAuthWindowPopFullScreen;
    } else if (authWindowPop == 1) {
        customModel.authWindowPop = NTESAuthWindowPopCenter;
    } else {
        customModel.authWindowPop = NTESAuthWindowPopBottom;
    }
    customModel.customizedTransition = [[dict objectForKey:@"customizedTransition"] boolValue];
    customModel.isPrivacyToastAutoEnabled = [[dict objectForKey:@"isPrivacyToastAutoEnabled"] boolValue];

    int closePopImgHeight = [[dict objectForKey:@"closePopImgHeight"] intValue];
    int closePopImgWidth = [[dict objectForKey:@"closePopImgWidth"] intValue];
    customModel.closePopImgWidth = closePopImgWidth;
    customModel.closePopImgHeight = closePopImgHeight;
    
    int closePopImgOriginY = [[dict objectForKey:@"closePopImgOriginY"] intValue];
    int closePopImgOriginX = [[dict objectForKey:@"closePopImgOriginX"] intValue];
    customModel.closePopImgOriginX = closePopImgOriginX;
    customModel.closePopImgOriginY = closePopImgOriginY;
    
    int authWindowCenterOriginX = [[dict objectForKey:@"authWindowCenterOriginX"] intValue];
    int authWindowCenterOriginY = [[dict objectForKey:@"authWindowCenterOriginY"] intValue];
    customModel.authWindowCenterOriginY = authWindowCenterOriginY;
    customModel.authWindowCenterOriginX = authWindowCenterOriginX;
    
    int popCenterCornerRadius = [[dict objectForKey:@"popCenterCornerRadius"] intValue];
    int popBottomCornerRadius = [[dict objectForKey:@"popBottomCornerRadius"] intValue];
    customModel.popBottomCornerRadius = popBottomCornerRadius;
    customModel.popCenterCornerRadius = popCenterCornerRadius;
    customModel.presentDirectionType = NTESPresentDirectionPresentSupportPush;
    
    
    customModel.hidesBottomBarWhenPushed = [[dict objectForKey:@"hidesBottomBarWhenPushed"] boolValue];
    customModel.openBackTapGestureRecognizer = [[dict objectForKey:@"openBackTapGestureRecognizer"] boolValue];
    
    customModel.popBackgroundColor = [[self ntes_colorWithHexString:[dict objectForKey:@"popBackgroundColor"]] colorWithAlphaComponent:[[dict objectForKey:@"alpha"] doubleValue]];
    
    UIViewController *rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
    
    if (!rootController) {
        NSArray *scenes = [UIApplication sharedApplication].connectedScenes.allObjects;
        UIWindowScene *scene = scenes.firstObject;
        rootController = scene.windows.firstObject.rootViewController;
    }
    
    customModel.currentVC = rootController;
    customModel.rootViewController = rootController;
    [[NTESQuickLoginManager sharedInstance] setupModel:customModel];
    
    int showPrivacyDialog = [[dict objectForKey:@"showPrivacyDialog"] intValue];
    if (showPrivacyDialog == 2) {
        customModel.prograssHUDBlock = ^(UIView * _Nullable prograssHUDBlock) {
            
        };
    } else if (showPrivacyDialog == 1) {
        customModel.prograssHUDBlock = ^(UIView * _Nullable prograssHUDBlock) {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"隐私协议请仔细阅读" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [NTESQuickLoginManager sharedInstance].model.checkedSelected = YES;
                [[NTESQuickLoginManager sharedInstance] authLoginButtonClick];
            }];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertController addAction:cancelAction];
            [alertController addAction:alertAction];
            
            if ([[NTESQuickLoginManager sharedInstance] getCarrier] == NTESCarrierTypeMobile) {
                [rootController.presentedViewController.presentedViewController presentViewController:alertController animated:YES completion:nil];
            }else {
                [rootController.presentedViewController presentViewController:alertController animated:YES completion:nil];
            }
            
            // [rootController.presentedViewController presentViewController:alertController animated:YES completion:nil];
        };
    } else if (showPrivacyDialog == 0) {
        customModel.toastWidth               = [[dict objectForKey:@"toastWidth"] intValue];
        customModel.toastHeight              = [[dict objectForKey:@"toastHeight"] intValue];
        customModel.toastBackgroundColor     = [self ntes_colorWithHexString:[dict objectForKey:@"toastBackgroundColor"]];
        customModel.toastMaskBackgroundColor = [self ntes_colorWithHexString:[dict objectForKey:@"toastMaskBackgroundColor"]];
        customModel.toastCornerRadius        = [[dict objectForKey:@"toastCornerRadius"] intValue];
        
        /// 标题
        customModel.toastTitleText          = [dict objectForKey:@"toastTitleText"];
        customModel.toastTitleTextColor     = [self ntes_colorWithHexString:[dict objectForKey:@"toastTitleTextColor"]];
        customModel.toastTitleFontSize      = [[dict objectForKey:@"toastTitleFontSize"] intValue];
        
        NSString *toastTitleFontWeight = [dict objectForKey:@"toastTitleFontWeight"];
        if ([toastTitleFontWeight isEqualToString:@"bold"]) {
            customModel.toastTitleFontWeight    = UIFontWeightBold;
        }
        if ([toastTitleFontWeight isEqualToString:@"thin"]) {
            customModel.toastTitleFontWeight    = UIFontWeightThin;
        }
        if ([toastTitleFontWeight isEqualToString:@"regular"]) {
            customModel.toastTitleFontWeight    = UIFontWeightRegular;
        }
        
        /// 内容
        customModel.toastContentPrefixText  = [dict objectForKey:@"toastContentPrefixText"];
        customModel.toastContentSuffixText  = [dict objectForKey:@"toastContentSuffixText"];
        customModel.toastContentTextColor   = [self ntes_colorWithHexString:[dict objectForKey:@"toastContentTextColor"]];
        customModel.toastProtocolTextColor   = [self ntes_colorWithHexString:[dict objectForKey:@"toastProtocolTextColor"]];
        customModel.toastContentFontSize    = [[dict objectForKey:@"toastContentFontSize"] intValue];
        customModel.toastContentLineSpacing = [[dict objectForKey:@"toastContentLineSpacing"] intValue];
        customModel.toastContentWordSpacing = [[dict objectForKey:@"toastContentWordSpacing"] intValue];

        NSString *toastContentFontWeight = [dict objectForKey:@"toastContentFontWeight"];
        if ([toastContentFontWeight isEqualToString:@"bold"]) {
            customModel.toastContentFontWeight    = UIFontWeightBold;
        }
        if ([toastContentFontWeight isEqualToString:@"thin"]) {
            customModel.toastContentFontWeight    = UIFontWeightThin;
        }
        if ([toastContentFontWeight isEqualToString:@"regular"]) {
            customModel.toastContentFontWeight    = UIFontWeightRegular;
        }
        
        /// 按钮组
        customModel.toastCancelWidth            = [[dict objectForKey:@"toastCancelWidth"] intValue];
        customModel.toastCancelHeight           = [[dict objectForKey:@"toastCancelHeight"] intValue];
        customModel.toastCancelText             = [dict objectForKey:@"toastCancelText"];
        customModel.toastCancelTextColor        = [self ntes_colorWithHexString:[dict objectForKey:@"toastCancelTextColor"]];
        customModel.toastCancelFontSize         = [[dict objectForKey:@"toastCancelFontSize"] intValue];
        customModel.toastCancelCornerRadius     = [[dict objectForKey:@"toastCancelCornerRadius"] intValue];
        customModel.toastCancelBackgroundColor  = [self ntes_colorWithHexString:[dict objectForKey:@"toastCancelBackgroundColor"]];
        customModel.toastCancelBorderColor      = [self ntes_colorWithHexString:[dict objectForKey:@"toastCancelBorderColor"]];
        
        NSString *toastCancelFontWeight         = [dict objectForKey:@"toastCancelFontWeight"];
        if ([toastCancelFontWeight isEqualToString:@"bold"]) {
            customModel.toastCancelFontWeight   = UIFontWeightBold;
        }
        if ([toastCancelFontWeight isEqualToString:@"thin"]) {
            customModel.toastCancelFontWeight   = UIFontWeightThin;
        }
        if ([toastCancelFontWeight isEqualToString:@"regular"]) {
            customModel.toastCancelFontWeight   = UIFontWeightRegular;
        }
        
        customModel.toastConfirmWidth            = [[dict objectForKey:@"toastConfirmWidth"] intValue];
        customModel.toastConfirmHeight           = [[dict objectForKey:@"toastConfirmHeight"] intValue];
        customModel.toastConfirmText             = [dict objectForKey:@"toastConfirmText"];
        customModel.toastConfirmTextColor        = [self ntes_colorWithHexString:[dict objectForKey:@"toastConfirmTextColor"]];
        customModel.toastConfirmFontSize         = [[dict objectForKey:@"toastConfirmFontSize"] intValue];
        customModel.toastConfirmCornerRadius     = [[dict objectForKey:@"toastConfirmCornerRadius"] intValue];
        customModel.toastConfirmBackgroundColor  = [self ntes_colorWithHexString:[dict objectForKey:@"toastConfirmBackgroundColor"]];
        customModel.toastConfirmBorderColor      = [self ntes_colorWithHexString:[dict objectForKey:@"toastConfirmBorderColor"]];
        NSString *toastConfirmFontWeight         = [dict objectForKey:@"toastConfirmFontWeight"];
        if ([toastConfirmFontWeight isEqualToString:@"bold"]) {
            customModel.toastConfirmFontWeight   = UIFontWeightBold;
        }
        if ([toastConfirmFontWeight isEqualToString:@"thin"]) {
            customModel.toastConfirmFontWeight   = UIFontWeightThin;
        }
        if ([toastConfirmFontWeight isEqualToString:@"regular"]) {
            customModel.toastConfirmFontWeight   = UIFontWeightRegular;
        }
        
        /// Space
        customModel.toastTitleToContentSpace    = [[dict objectForKey:@"toastTitleToContentSpace"] intValue];
        customModel.toastContentToButtonSpace   = [[dict objectForKey:@"toastContentToButtonSpace"] intValue];
        
        int toastEdgeInsetsTop      = [[dict objectForKey:@"toastEdgeInsetsTop"] intValue];
        int toastEdgeInsetsBottom   = [[dict objectForKey:@"toastEdgeInsetsBottom"] intValue];
        int toastEdgeInsetsLeft     = [[dict objectForKey:@"toastEdgeInsetsLeft"] intValue];
        int toastEdgeInsetsRight    = [[dict objectForKey:@"toastEdgeInsetsRight"] intValue];
        customModel.toastEdgeInsets = UIEdgeInsetsMake(toastEdgeInsetsTop, toastEdgeInsetsLeft, toastEdgeInsetsBottom, toastEdgeInsetsRight);
    }
    
    customModel.backActionBlock = ^(int backType) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:@"backAction" forKey:@"action"];
        if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
            [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
        }
    };
    
    customModel.closeActionBlock = ^{
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:@"closeAction" forKey:@"action"];
        if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
            [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
        }
    };
    customModel.loginActionBlock = ^(BOOL isChecked) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:@"loginAction" forKey:@"action"];
        [dict setValue:@(isChecked) forKey:@"checked"];
        if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
            [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
        }
    };
    customModel.checkActionBlock = ^(BOOL isChecked) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:@"checkedAction" forKey:@"action"];
        [dict setValue:@(isChecked) forKey:@"checked"];
        if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
            [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
        }
        
    };
    customModel.privacyActionBlock = ^(int privacyType) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        NSString *privacy;
        if (privacyType == 0) {
            privacy = @"appDPrivacy";
        } else if (privacyType == 1) {
            privacy = @"appFPrivacy";
        } else if (privacyType == 2) {
            privacy = @"appSPrivacy";
        }
        [dict setValue:privacy forKey:@"action"];
        if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
            [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
        };
    };
    
    CGFloat authWindowHeight = [[dict objectForKey:@"authWindowHeight"] floatValue];
    customModel.authWindowHeight = authWindowHeight;
    CGFloat authWindowWidth = [[dict objectForKey:@"authWindowWidth"] floatValue];
    customModel.authWindowWidth = authWindowWidth;
    customModel.contentMode = [[dict objectForKey:@"contentMode"] intValue];
    customModel.appPrivacyLineSpacing =  [[dict objectForKey:@"appPrivacyLineSpacing"] intValue];
    customModel.appPrivacyWordSpacing =  [[dict objectForKey:@"appPrivacyWordSpacing"] intValue];
}

- (void)buttonDidTipped:(UIButton *)sender {
    NSArray *option = [self.option objectForKey:@"widgets"];
    NSDictionary *action = option[sender.tag];
    NSString *actions = [action objectForKey:@"action"];
    [self.callBackDict setValue:actions forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(self.callBackDict);
    }
}

- (void)labelDidTipped:(UITapGestureRecognizer *)tap {
    UILabel *label = (UILabel *)tap.view;
    NSArray *option = [self.option objectForKey:@"widgets"];
    NSDictionary *action = option[label.tag];
    NSString *actions = [action objectForKey:@"action"];
    [self.callBackDict setValue:actions forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(self.callBackDict);
    }
}

- (NSString *)getSDKVersion {
    return [[NTESQuickLoginManager sharedInstance] getSDKVersion];
}

/**
 *  @说明        加载授权页。
 */
- (void)authViewDidLoad {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"authViewDidLoad" forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
    }
}

/**
 *  @说明        授权页将要出现。
 */
- (void)authViewWillAppear {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"authViewWillAppear" forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
    }
}

/**
 *  @说明        授权页已经出现。
 */
- (void)authViewDidAppear {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"authViewDidAppear" forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
    }
}

/**
 *  @说明        授权页将要消失。
 */
- (void)authViewWillDisappear {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"authViewWillDisappear" forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
    }
}

/**
 *  @说明        授权页已经消失。
 */
- (void)authViewDidDisappear {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"authViewDidDisappear" forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
    }
}

/**
 *  @说明        授权页销毁。
 */
- (void)authViewDealloc {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"authViewDealloc" forKey:@"action"];
    if ([QuickpassFlutterPlugin sharedInstance].eventSink) {
        [QuickpassFlutterPlugin sharedInstance].eventSink(dict);
    }
}

- (nullable UIColor *)ntes_colorWithHexString:(NSString *)string {
    return [self ntes_colorWithHexString:string alpha:1.0f];
}

- (nullable UIColor *)ntes_colorWithHexString:(NSString *)string alpha:(CGFloat)alpha {
    NSString *pureHexString = [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    if ([pureHexString hasPrefix:[@"#" uppercaseString]] || [pureHexString hasPrefix:[@"#" lowercaseString]]) {
        pureHexString = [pureHexString substringFromIndex:1];
    }
    
    CGFloat r, g, b, a;
    if (ntes_hexStrToRGBA(string, &r, &g, &b, &a)) {
        return [UIColor colorWithRed:r green:g blue:b alpha:a];
    }
    return nil;
}

static BOOL ntes_hexStrToRGBA(NSString *str, CGFloat *r, CGFloat *g, CGFloat *b, CGFloat *a) {
    NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    str = [[str stringByTrimmingCharactersInSet:set] uppercaseString];
    if ([str hasPrefix:@"#"]) {
        str = [str substringFromIndex:1];
    } else if ([str hasPrefix:@"0X"]) {
        str = [str substringFromIndex:2];
    }
    
    NSUInteger length = [str length];
    //         RGB            RGBA          RRGGBB        RRGGBBAA
    if (length != 3 && length != 4 && length != 6 && length != 8) {
        return NO;
    }
    
    //RGB,RGBA,RRGGBB,RRGGBBAA
    if (length < 5) {
        *r = ntes_hexStrToInt([str substringWithRange:NSMakeRange(0, 1)]) / 255.0f;
        *g = ntes_hexStrToInt([str substringWithRange:NSMakeRange(1, 1)]) / 255.0f;
        *b = ntes_hexStrToInt([str substringWithRange:NSMakeRange(2, 1)]) / 255.0f;
        if (length == 4) {
            *a = ntes_hexStrToInt([str substringWithRange:NSMakeRange(3, 1)]) / 255.0f;
        } else {
            *a = 1;
        }
    } else {
        *r = ntes_hexStrToInt([str substringWithRange:NSMakeRange(0, 2)]) / 255.0f;
        *g = ntes_hexStrToInt([str substringWithRange:NSMakeRange(2, 2)]) / 255.0f;
        *b = ntes_hexStrToInt([str substringWithRange:NSMakeRange(4, 2)]) / 255.0f;
        if (length == 8) {
            *a = ntes_hexStrToInt([str substringWithRange:NSMakeRange(6, 2)]) / 255.0f;
        } else {
            *a = 1;
        }
    }
    return YES;
}

static inline NSUInteger ntes_hexStrToInt(NSString *str) {
    uint32_t result = 0;
    sscanf([str UTF8String], "%X", &result);
    return result;
}

- (UIImage *)loadImageWithName:(NSString *)name {
    UIImage *image = [UIImage imageNamed:name];
    return image;
}

@end
